const db = require('../DBcofig/DBConnection')
module.exports = {
    setall(req, res) {
        let { page, limit, search } = req.query
        let sql = 'select * from patients_with P,attendance_card A,department D,department_one DE where P.card_id=A.card_id and P.patients_department=D.department_id and D.department_id=DE.department_one_id '
        let arr = []
        db.dbconfig(res, sql, arr, function (data) {
            // console.log(data);
            if (data != null) {
                res.send({
                    code: 200,
                    mag: "查询成功",
                    data
                })
            } else {
                res.send({
                    code: 400,
                    mag: "查询失败",
                })
            }

        })


    },
    setalltable(req, res) {
        let { startDate, endDate, radio } = req.query
        let sql = 'select * from patients_with P,attendance_card A,department D,department_one DE where P.card_id=A.card_id and P.patients_department=D.department_id and D.department_id=DE.department_one_id '
        let arr = []
        // let radios = (radio)
        // console.log(req.query);

        if (startDate != undefined && endDate != undefined) {
            sql += ` and  patients_ClinicDate >=?  and  patients_ClinicDate <?`
            arr.push(startDate, endDate)

        }
        if (radio != undefined && radio > 0) {
            sql += ` and patients_status=?`
            arr.push(parseInt(radio))

        }
        db.dbconfig(res, sql, arr, function (data) {
            // console.log(data);
            if (data != null) {
                res.send({
                    code: 200,
                    mag: "查询成功",
                    data
                })
            } else {
                res.send({
                    code: 400,
                    mag: "查询失败",
                })
            }

        })


    },
    selecttable(req, res) {
        let { id, search, startDate, endDate } = req.query
        console.log(req.query);
        let sql = 'select * from formxinxi,pay_cost,attendance_card ,patients_with where pay_cost.formid=formxinxi.id and pay_cost.patients_id=patients_with.patients_id and pay_cost.card_number=attendance_card.card_id '
        let arr = []

        if (id != undefined) {
            sql += ` and patients_with.card_id= ?`
            arr.push(parseInt(id))
        }
        if (search != undefined) {
            sql += ` and pay_patient_name like ?`
            arr.push(search + '%')
        }
        if (startDate != undefined && endDate != undefined) {
            sql += ` and  Operating_time >=?  and  Operating_time <?`
            arr.push(startDate, endDate)

        }

        db.dbconfig(res, sql, arr, function (data) {

            if (data != null) {
                res.send({
                    code: 200,
                    mag: "查询成功",
                    data
                })
            } else {
                res.send({
                    code: 400,
                    mag: "查询失败",
                })
            }

        })

    },

    slectform(req, res) {
        let { page, limit, search } = req.query
        let sql = 'select * from formxinxi'
        let arr = []
        db.dbconfig(res, sql, arr, function (data) {
            // console.log(data);
            if (data != null) {
                res.send({
                    code: 200,
                    mag: "查询成功",
                    data
                })
            } else {
                res.send({
                    code: 400,
                    mag: "查询失败",
                })
            }

        })


    },
    getCostPay(req, res) {
        let { page, limit, search } = req.query
        let sql = 'select * from formxinxi,pay_cost,attendance_card ,patients_with where pay_cost.formid=formxinxi.id and pay_cost.patients_id=patients_with.patients_id and pay_cost.card_number=attendance_card.card_id'
        let arr = []
        //    let sql='select * from pay_cost'
        db.dbconfig(res, sql, arr, function (data) {
            // console.log(data);
            if (data != null) {
                res.send({
                    code: 200,
                    mag: "查询成功",
                    data
                })
            } else {
                res.send({
                    code: 400,
                    mag: "查询失败",
                })
            }

        })


    }
}